home *** CD-ROM | disk | FTP | other *** search
/ PC-X 1997 October / pcx14_9710.iso / swag / delphi.swg / 0164_Adjust the speaker volume in code.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-08-30  |  6.8 KB  |  225 lines

  1. {******** unit1.pas  ********}
  2. unit unit1;
  3. interface
  4. uses
  5.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  6.   StdCtrls, ExtCtrls, FileCtrl, MPlayer, MMSystem, Spin, ComCtrls;
  7. type
  8.   TForm1 = class(TForm)
  9.     MediaPlayer1: TMediaPlayer;
  10.     DriveComboBox1: TDriveComboBox;
  11.     DirectoryListBox1: TDirectoryListBox;
  12.     FileListBox1: TFileListBox;
  13.     Panel1: TPanel;
  14.     CheckBox1: TCheckBox;
  15.     GroupBox2: TGroupBox;
  16.     TrackBar1: TTrackBar;
  17.     procedure FileListBox1DblClick(Sender: TObject);
  18.     procedure FileListBox1Click(Sender: TObject);
  19.     procedure MediaPlayer1Click(Sender: TObject; Button: TMPBtnType;
  20.       var DoDefault: Boolean);
  21.     procedure FormCreate(Sender: TObject);
  22.     procedure MediaPlayer1Notify(Sender: TObject);
  23.     procedure FormDestroy(Sender: TObject);
  24.     procedure FormShow(Sender: TObject);
  25.     procedure TrackBar1Change(Sender: TObject);
  26.     function GetTrackBar: integer;
  27.   private
  28.     { Private declarations }
  29.   public
  30.     { Public declarations }
  31.   end;
  32. var
  33.   Form1: TForm1;
  34.   pCurrentVolumeLevel: PDWord;
  35.   CurrentVolumeLevel: DWord;
  36.   VolumeControlHandle: hWnd;
  37. implementation
  38. {$R *.DFM}
  39. procedure TForm1.FileListBox1DblClick(Sender: TObject);
  40. begin
  41.   if checkbox1.checked then
  42.      mediaplayer1.DisplayRect := Rect(0,0, Panel1.Width, Panel1.Height);
  43.   mediaplayer1.play;
  44. end;
  45. procedure TForm1.FileListBox1Click(Sender: TObject);
  46. begin
  47.   mediaplayer1.filename := FileListBox1.items[filelistbox1.itemindex];
  48.   mediaplayer1.open;
  49. end;
  50. procedure TForm1.MediaPlayer1Click(Sender: TObject; Button: TMPBtnType;
  51.   var DoDefault: Boolean);
  52. begin
  53.   case Button of
  54.     btPlay :
  55.     if checkbox1.checked then
  56.        mediaplayer1.DisplayRect := Rect(0,0, Panel1.Width, Panel1.Height);
  57.   end;
  58. end;
  59. procedure TForm1.FormCreate(Sender: TObject);
  60. begin
  61.   DirectoryListBox1.Directory := 'd:\sound';
  62.   mediaplayer1.notify := true;
  63.   New(pCurrentVolumeLevel);
  64. end;
  65. procedure TForm1.MediaPlayer1Notify(Sender: TObject);
  66. begin
  67.   Panel1.refresh;
  68.   with Mediaplayer1 do
  69.     if NotifyValue = nvAborted then begin
  70.        filename := FileListBox1.items[filelistbox1.itemindex];
  71.        open;
  72.     end;
  73. end;
  74. procedure TForm1.FormDestroy(Sender: TObject);
  75. begin
  76.   dispose(pCurrentVolumeLevel);
  77. end;
  78. function TForm1.GetTrackBar: integer;
  79. begin
  80.   result := 65535 div Trackbar1.max;
  81. end;
  82. procedure TForm1.FormShow(Sender: TObject);
  83. begin
  84.   VolumeControlHandle := FindWindow('Volume Control', nil);
  85.   WaveOutGetVolume(VolumeControlHandle, pCurrentVolumeLevel);
  86.   CurrentVolumeLevel := pCurrentVolumeLevel^;
  87.   Trackbar1.position := LoWord(CurrentVolumeLevel) DIV GetTrackBar;
  88. end;
  89. procedure TForm1.TrackBar1Change(Sender: TObject);
  90. begin
  91.   CurrentVolumeLevel := Trackbar1.position * GetTrackBar shl 16;
  92.   CurrentVolumeLevel := CurrentVolumeLevel + (Trackbar1.position * GetTrackBar);
  93.   if WaveOutSetVolume(VolumeControlHandle, CurrentVolumeLevel) <> 0 then
  94.     ShowMessage('Cannot adjust Volume.');
  95. end;
  96. end.
  97. {********** unit1.dfm  *********}
  98. object Form1: TForm1
  99.   Left = 202
  100.   Top = 109
  101.   Width = 402
  102.   Height = 321
  103.   ActiveControl = DriveComboBox1
  104.   BorderIcons = [biSystemMenu]
  105.   Caption = 'Mediaplayer Example - Created using Delphi 2.0'
  106.   Font.Color = clWindowText
  107.   Font.Height = -11
  108.   Font.Name = 'MS Sans Serif'
  109.   Font.Style = []
  110.   Icon.Data = {
  111.     0000010001002020100000000000E80200001600000028000000200000004000
  112.     0000010004000000000080020000000000000000000000000000000000000000
  113.     0000000080000080000000808000800000008000800080800000C0C0C0008080
  114.     80000000FF0000FF000000FFFF00FF000000FF00FF00FFFF0000FFFFFF008888
  115.     888888888888888888888888888888888888888888880000FEEFEFF000088888
  116.     8888888888880000FEEFEFF0000888888888888888880770EFFEFEE070088888
  117.     8888888888880000FEEFEFF00008888888888888888807700000000070088888
  118.     888888888888077000000000700888888888888888880000FFFFFFF000088888
  119.     8888888888880770EFFEFEE0700888888888888888880000FEEFEFF000088888
  120.     8888888888880000FEEFEFF0000888888888888888880770EFFEFEE070088888
  121.     888888888888000000000000000888808888888888880770FFFFFFF070088880
  122.     8888888888880770FFFFFFF0700880000888888088880000FEEFEFF000088880
  123.     0008800008880770EFFEFEE0700888888008888000080000FEEFEFF000088888
  124.     8008888000080000FEEFEFF00008888880088888800807700000000070088888
  125.     8008888880080000FFFFFFF0000888888008888880080770EFFEFEE070088888
  126.     8008888880080770EFFEFEE0700888888008888880080000FEEFEFF000088888
  127.     8008888880088888888888888888888880000000000888888888888888888888
  128.     8000000000088888888888888888888880033333300888888888888888888888
  129.     8000000000088888888888888888888888888888888888888888888888888888
  130.     8888888888888888888888888888888888888888888888888888888888880000
  131.     0000000000000000000000000000000000000000000000000000000000000000
  132.     0000000000000000000000000000000000000000000000000000000000000000
  133.     0000000000000000000000000000000000000000000000000000000000000000
  134.     000000000000000000000000000000000000000000000000000000000000}
  135.   OnCreate = FormCreate
  136.   OnDestroy = FormDestroy
  137.   OnShow = FormShow
  138.   PixelsPerInch = 96
  139.   TextHeight = 13
  140.   object MediaPlayer1: TMediaPlayer
  141.     Left = 152
  142.     Top = 240
  143.     Width = 141
  144.     Height = 33
  145.     VisibleButtons = [btPlay, btPause, btStop, btPrev, btBack]
  146.     Display = Panel1
  147.     ParentShowHint = False
  148.     ShowHint = True
  149.     TabOrder = 0
  150.     OnClick = MediaPlayer1Click
  151.     OnNotify = MediaPlayer1Notify
  152.   end
  153.   object DriveComboBox1: TDriveComboBox
  154.     Left = 0
  155.     Top = 0
  156.     Width = 145
  157.     Height = 19
  158.     DirList = DirectoryListBox1
  159.     TabOrder = 1
  160.   end
  161.   object DirectoryListBox1: TDirectoryListBox
  162.     Left = 0
  163.     Top = 22
  164.     Width = 145
  165.     Height = 114
  166.     FileList = FileListBox1
  167.     ItemHeight = 16
  168.     TabOrder = 2
  169.   end
  170.   object FileListBox1: TFileListBox
  171.     Left = 0
  172.     Top = 139
  173.     Width = 145
  174.     Height = 141
  175.     ItemHeight = 13
  176.     Mask = '*.wav;*.avi'
  177.     MultiSelect = True
  178.     TabOrder = 3
  179.     OnClick = FileListBox1Click
  180.     OnDblClick = FileListBox1DblClick
  181.   end
  182.   object Panel1: TPanel
  183.     Left = 152
  184.     Top = 8
  185.     Width = 241
  186.     Height = 225
  187.     TabOrder = 4
  188.   end
  189.   object CheckBox1: TCheckBox
  190.     Left = 218
  191.     Top = 275
  192.     Width = 76
  193.     Height = 17
  194.     Caption = 'Stretch AVI'
  195.     State = cbChecked
  196.     TabOrder = 5
  197.   end
  198.   object GroupBox2: TGroupBox
  199.     Left = 296
  200.     Top = 234
  201.     Width = 97
  202.     Height = 53
  203.     Caption = 'Volume'
  204.     TabOrder = 6
  205.     object TrackBar1: TTrackBar
  206.       Left = 2
  207.       Top = 11
  208.       Width = 93
  209.       Height = 34
  210.       Max = 26
  211.       Orientation = trHorizontal
  212.       ParentShowHint = False
  213.       Frequency = 1
  214.       Position = 0
  215.       SelEnd = 0
  216.       SelStart = 0
  217.       ShowHint = True
  218.       TabOrder = 0
  219.       TickMarks = tmBoth
  220.       TickStyle = tsAuto
  221.       OnChange = TrackBar1Change
  222.     end
  223.   end
  224. end
  225.